﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitBase.WinForm;
using YJKRevitView;
using YJKRevitStairs.HYElevator.Manage;

namespace YJKRevitStairs.StairsModel
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdPutElevator : IExternalCommand
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			if (Convert.ToInt32(commandData.Application.Application.VersionNumber) < 2015)
			{
				message = "此功能只在Revit2015及其以上版本可用。";
				return Autodesk.Revit.UI.Result.Failed;
			}
			CmdViewType types = (CmdViewType)11;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			if (CmdPutElevator._hWndRevit == null)
			{
				CmdPutElevator._hWndRevit = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
			}
			HideWarningKit @object = new HideWarningKit("放置电梯");
			commandData.Application.Application.FailuresProcessing += @object.OnFailuresProcessing;
			new ElevatorManger(commandData).Run();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static WindowHandle _hWndRevit;
	}
}
